<template>
  <div class="page">
    <div class="head">
      <h1>{{ $t('收支记录') }}</h1>
    </div>
    <group gutter="0" class="filter-wrap">
      <cell :title="'全部'" is-link :border-intent="false" @click.native="showFilter = !showFilter" :arrow-direction="showFilter ? 'up' : 'down'"></cell>
      <ul class="filter" :class="{'animate': showFilter}">
        <li v-for="(item,index) in filters" :class="{'active': item.value == active}" @click="changeFilter(item.value)" :key="index">{{item.name}}</li>
      </ul>
    </group>
    <div class="panel">
      <ul class="list">
        <li v-for="(item,index) in records" :key="index">
          <div class="info">
            <p>{{ item | recordTypeDict }}</p>
            <span>{{ item.createTime | formatTime }}</span>
          </div>
          <div class="status">
            <p>{{ item | withDrawStatus }}</p>
            <span :class="isPositive(item.type) ? 'green':'red'">{{ item.type | pointPrefix }}{{ item.amount }}</span>
          </div>
        </li>
        <infinite-loading @infinite="initData" ref="infiniteLoading2">
          <span slot="no-more"></span>
          <div slot="no-results">
            <br>
            <empty></empty>
          </div>
          <spinner slot="spinner" type="lines"></spinner>
        </infinite-loading>
      </ul>
    </div>
  </div>
</template>

<script>
  import {
    Spinner,
    Cell,
    Group
  } from 'vux'
  import empty from './common/empty.vue'
  import InfiniteLoading from 'vue-infinite-loading';
  export default {
    components: {
      empty,
      InfiniteLoading,
      Spinner,
      Cell,
      Group
    },
    data() {
      return {
        records: [],
        current: 1,
        // filters: ['全部', '充值', '提现', '掘金收益', '出售猴子手续费', '交配手续费', '取消扣款', '深山修炼奖励', '喂食猴子', '喂食手续费', '提现手续费', '买道具消费', '卖道具收入', '买蟠桃消费', '卖蟠桃收入', '道具交易手续费', '出售小猴收入', '购买小猴支出', '出售小猴生育收入', '购买小猴生育支出', '抽奖','增值服务','奖励'],
        filters: [
          {name: '全部', value: 0},
          {name: '充值', value: 1},
          {name: '提现', value: 2},
          {name: '出售手续费', value: 4},
          {name: '交配手续费', value: 5},
          {name: '买道具消费', value: 11},
          {name: '卖道具收入', value: 12},
          {name: '道具交易手续费', value: 15},
          {name: '出售小猴收入', value: 16},
          {name: '购买小猴生育支出', value: 17},
          {name: '生育收入', value: 18},
          {name: '生育支出', value: 19},
          {name: '采集', value: 22},
          {name: '城堡收益', value: 23},
          {name: '抽奖收益', value: 24},
          {name: '增值服务', value: 25},
          {name: '奖励', value: 26},
          {name: '攻城奖励', value: 27},
          {name: '挂单扣减', value: 28},
          {name: '取消挂单', value: 29},
          {name: '挂单成交', value: 30},
          {name: '成交手续费', value: 31},
        ],
        active: 0,
        showFilter: false
      }
    },
    mounted() {
      this.$nextTick(function() {
      });
    },
    methods: {
      initData($state) {
        this.$http
          .post(`/game/accountRecordPage`, {
            current: this.current,
            type: this.active
          })
          .then(res => {
            if (res.code == 200) {
              if (res.result.total > 0) {
                this.records = this.records.concat(res.result.records);
                $state.loaded();
                if (res.result.current < res.result.pages) {
                  this.current += 1;
                } else {
                  $state.complete();
                }
              } else {
                $state.complete();
              }
            } else {}
          })
          .catch(function(error) {});
      },
      isPositive(type) {
        var positive = [1,3,7,12,14,16,18,23,24,26,27,29,30]
        return positive.indexOf(type) > -1
      },
      changeFilter(index) {
        this.active = index;
        this.current = 1;
        this.records = []
        this.$refs.infiniteLoading2.$emit('$InfiniteLoading:reset');
      }
    }
  }
</script>

<style lang="scss" scoped>
  .panel {
    padding-bottom: 100px;
  }
  .filter-wrap {
    margin: 0 8px 10px;
  }
  .filter {
    padding: 0 12px 0;
    font-size: 12px;
    max-height: 0;
    transition: .3s;
    li {
      background: #f6f6f6;
      margin: 0 5px 5px 0;
      padding: 2px 5px;
      border-radius: 2px;
      display: inline-block;
      color: #7e7e7e;
      transition: .5s;
    }
    .active {
      color: #fff;
      background: $tmdark;
    }
  }
  .animate {
    max-height: 150px;
  }
  .list {
    li {
      border-bottom: 1px solid #dfdfdf;
      display: flex;
      justify-content: space-between;
      align-items: flex-end;
      padding: 5px 0;
      .info {
        color: $tmdark;
        p {
          font-size: 17px;
        }
        span {
          font-size: 14px;
        }
      }
      .status {
        text-align: right;
      }
      &>span {
        font-size: 20px;
      }
      .red {
        color: $red;
      }
      .green {
        color: $green;
      }
    }
  }
</style>
<style lang="scss">
  .filter-wrap {
    // margin: 0 8px 10px;
    .vux-no-group-title {
      border-radius: 8px;
      overflow: hidden;
      box-shadow: 0px 4px 12px 0px rgba(158, 158, 158, 0.3);
    }
    .weui-cells:before {
      display: none;
    }
  }
</style>